package src

import (
 "net/http"
 "encoding/json"
 "fmt"
)

type finesParmas struct {
	SupplierBillID string `json:"SupplierBillID"`
}

func (f *finesParmas) fill(body []byte) {
	err := json.Unmarshal(body, f)
	if err!=nil {
		panic("unmarchalling finesParmas error")
	}
}

func payFineHandler(w http.ResponseWriter, r *http.Request) {
	emp, body := ParseParams(r)
	var session *string = nil
	if emp.Auth !=nil {
		session = emp.Auth.Session
	}
	
	var fineParam finesParmas
	fineParam.fill(body)

	var response Response
	if (session==nil){
		response = Response{ session, 403, "Unauthorized", ""} 
	} else if (len(fineParam.SupplierBillID)==0){
		response = Response{ session, 100, "give me SupplierBillID in params", ""}
	}else {
		response = Response{ session, 0, "", "OK"} 
	}
	
	obj,_ := json.Marshal(response)
	fmt.Fprint(w, string(obj))
}
